package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.RoomInfo;
import com.ruoyi.system.service.IRoomInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间信息Controller
 */
@RestController
@RequestMapping("/system/room")
public class RoomInfoController extends BaseController {
    private String prefix = "system/room";

    @Autowired
    private IRoomInfoService roomInfoService;

    @GetMapping()
    public String room() {
        return prefix + "/room";
    }

    /**
     * 查询房间信息列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoomInfo roomInfo) {
        startPage();
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        return getDataTable(list);
    }

    /**
     * 新增房间信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存房间信息
     */
    @Log(title = "房间信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody RoomInfo roomInfo) {
        roomInfo.setCreateTime(new Date());
        roomInfo.setRoomType("2");
        return toAjax(roomInfoService.insertRoomInfo(roomInfo));
    }

    /**
     * 修改房间信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        RoomInfo roomInfo = roomInfoService.selectRoomInfoById(id);
        mmap.put("roomInfo", roomInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存房间信息
     */
    @Log(title = "房间信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody RoomInfo roomInfo) {
        roomInfo.setUpdateTime(new Date());
        return toAjax(roomInfoService.updateRoomInfo(roomInfo));
    }

    /**
     * 删除房间信息
     */
    @Log(title = "房间信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String ids) {
        return toAjax(roomInfoService.deleteRoomInfoByIds(new Long[]{Long.parseLong(ids)}));
    }

    /**
     * 获取房间信息详细信息
     */
    @GetMapping("/detail/{id}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(roomInfoService.selectRoomInfoById(id));
    }
} 